package com.yuan.dao.autofetch.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.yuan.dao.autofetch.AutoFetchDao;
import com.yuan.fetch.AutoFetch;

public class AutoFetchDaoImpl extends SqlMapClientTemplate implements AutoFetchDao {

	@SuppressWarnings("unchecked")
	public List<AutoFetch> readAll() {
		return this.queryForList("AutoFetch.readAll");
	}

	public void save(AutoFetch autoFetch) throws DataAccessException {
		this.insert("AutoFetch.save", autoFetch);
	}

	@SuppressWarnings("unchecked")
	public List<AutoFetch> readNeedFetch(String ownSign, int fetchNum, int queueNum, String condition) throws DataAccessException {

		Map<String, Object> args = new HashMap<String, Object>();
		args.put("ownSign", ownSign);
		args.put("fetchNum", fetchNum);
		args.put("queueNum", queueNum);
		args.put("condition", condition);

		return this.queryForList("AutoFetch.readnNeedFetch", args);
		
	}

	public void updateStatus(Integer id, Boolean isFetched) throws DataAccessException {
		Map<String, Object> args = new HashMap<String, Object>();
		args.put("id", id);
		args.put("fetched", isFetched);

		update("AutoFetch.updateStatus", args);
	}

	public void updateAllStatus(Boolean isFetched) throws DataAccessException {
		Map<String, Object> args = new HashMap<String, Object>();
		args.put("fetched", isFetched);
		update("AutoFetch.updateAllStatus", args);
		
	}

}
